<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <BUtton onclick="openwin()">打开新窗口，3s后自动关闭</BUtton>
</body>

</html>
<script>
  function openwin() {
    var mywindow = window.open("", "", "width=300,heigh=200");
    mywindow.document.write("新窗口");
    setTimeout(() => {
      mywindow.close()
    }, 3000);
  }
</script>